import {mergeOptions} from '../util/mergeOptions.js'
let globalAPI=['component','filter','derective','mixin']
function initGlobalAPI(Vue){
   
   Vue.options={}
   Vue.options._base=Vue
   Vue.extend=initExtend
   globalAPI.forEach(api=>{
      Vue.options[api+'s']={}
      switch(api){
         case 'component':
             Vue.component=initComponent
             break
         case 'filter':
             Vue.filter=initFilter
            break;
         case 'derective':
             Vue.derective=initDerective
            break
         case 'mixin':
            // Vue.mixin=function (mixin){
            //    this.options=mergeOptions(this.options,mixin)
            // }
            Vue.mixin=initMixin
            break
         default:
            break
      }
   })
}
let cid=0
function initExtend(component){
    let sub=function vueCompoent(options){
       //vue的一个实例
       this._init(options)
    }
    //让sub的原型链指向Vue
    sub.prototype=Object.create(this.prototype)
    sub.cid=cid++
    sub.prototype.constructor=sub
    sub.options=mergeOptions(this.options,component)
    return sub
}
function initComponent(id,component){
   component=this.options._base.extend(component)
   this.options.components[id]=component
}
function initFilter(){

}
function initDerective(){

}
function initMixin(mixin){
   this.options=mergeOptions(this.options,mixin)
}
export default initGlobalAPI